﻿'------------------------------------------
' ArrowLine.cs (c) 2007 by Charles Petzold
'------------------------------------------

Imports System
Imports System.Windows
Imports System.Windows.Media

''' <summary>
''' Dessine une ligne droite entre deux points avec une flèche optionnelle aux extrêmités
''' </summary>
Public Class ArrowLine
    Inherits ArrowLineBase

    ''' <summary>
    ''' Identifie la Dependency Property X1.
    ''' </summary>
    Public Shared ReadOnly X1Property As DependencyProperty =
        DependencyProperty.Register("X1",
                                    GetType(Double),
                                    GetType(ArrowLine),
                                    New FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure))

    ''' <summary>
    '''     Gets or sets the x-coordinate of the ArrowLine start point.
    ''' </summary>
    Public Property X1 As Double
        Get
            Return DirectCast(GetValue(X1Property), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(X1Property, value)
        End Set
    End Property

    ''' <summary>
    ''' Identifie la Dependency Property Y1.
    ''' </summary>
    Public Shared ReadOnly Y1Property As DependencyProperty =
        DependencyProperty.Register("Y1",
                                    GetType(Double),
                                    GetType(ArrowLine),
                                    New FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure))

    ''' <summary>
    '''     Gets or sets the y-coordinate of the ArrowLine start point.
    ''' </summary>
    Public Property Y1 As Double
        Get
            Return DirectCast(GetValue(Y1Property), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(Y1Property, value)
        End Set
    End Property

    ''' <summary>
    ''' Identifie la Dependency Property X2.
    ''' </summary>
    Public Shared ReadOnly X2Property As DependencyProperty =
        DependencyProperty.Register("X2",
                                    GetType(Double),
                                    GetType(ArrowLine),
                                    New FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure))

    ''' <summary>
    '''     Gets or sets the x-coordinate of the ArrowLine end point.
    ''' </summary>
    Public Property X2 As Double
        Get
            Return DirectCast(GetValue(X2Property), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(X2Property, value)
        End Set
    End Property

    ''' <summary>
    ''' Identifie la Dependency Property Y2.
    ''' </summary>
    Public Shared ReadOnly Y2Property As DependencyProperty =
        DependencyProperty.Register("Y2",
                                    GetType(Double),
                                    GetType(ArrowLine),
                                    New FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure))

    ''' <summary>
    '''     Gets or sets the y-coordinate of the ArrowLine end point.
    ''' </summary>
    Public Property Y2 As Double
        Get
            Return DirectCast(GetValue(Y2Property), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(Y2Property, value)
        End Set
    End Property

    ''' <summary>
    '''     Gets a value that represents the Geometry of the ArrowLine.
    ''' </summary>
    Protected Overloads Overrides ReadOnly Property DefiningGeometry() As Geometry
        Get
            ' Clear out the PathGeometry.
            pathgeo.Figures.Clear()

            ' Define a single PathFigure with the points.
            pathfigLine.StartPoint = New Point(X1, Y1)
            polysegLine.Points.Clear()
            polysegLine.Points.Add(New Point(X2, Y2))
            pathgeo.Figures.Add(pathfigLine)

            ' Call the base property to add arrows on the ends.
            Return MyBase.DefiningGeometry
        End Get
    End Property

End Class